/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.Model.Repositories;

import com.Model.Campo;
import com.thoughtworks.xstream.XStream;
import java.util.List;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Fellipe
 */
public class CampoRepository {

    private com.Clientes.Campo.Campo_Service service = new com.Clientes.Campo.Campo_Service();
    private com.Clientes.Campo.Campo port = service.getCampoPort();
    private XStream xstream = new XStream();

//Clientes WEB    
    public void create(Campo c) {
        port.create(toXML(c));
    }

    public List<Campo> readNomes() {
        return fromXMLList(port.readNomes());
    }
    
    public Campo read(int chaveCampo) {
        return fromXML(port.read(chaveCampo));
    }

    public void update(Campo c) {
//        System.out.println(toXML(c));
        port.update(toXML(c));
    }

    public void delete(int cod) {
        //port.delete(cod);
        System.out.println("Deletou campo " + cod);
    }

//Funções XML
    private String toXML(Campo c) {
        return xstream.toXML(c);
    }

    private Campo fromXML(String xml) {
        return (Campo) xstream.fromXML(xml);
    }
    
    private List<Campo> fromXMLList(String xml) {
        return (List<Campo>) xstream.fromXML(xml);
    }
    
}
